package com.magical.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Files {
    private String fileId;

    private String fileName;

    private Integer fileSize;

    private String fileFullSize;

    private Integer userId;

    private String fatherId;

    private String fullPath;

    private Integer filetypeId;

    private Date uploadTime;

    public int getDelected() {
        return delected;
    }

    public void setDelected(int delected) {
        this.delected = delected;
    }

    private int delected;

    public String getFileId() {
        return fileId;
    }

    public void setFileId(String fileId) {
        this.fileId = fileId;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public Integer getFileSize() {
        return fileSize;
    }

    public void setFileSize(Integer fileSize) {
        this.fileSize = fileSize;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getFatherId() {
        return fatherId;
    }

    public void setFatherId(String fatherId) {
        this.fatherId = fatherId;
    }

    public String getFullPath() {
        return fullPath;
    }

    public void setFullPath(String fullPath) {
        this.fullPath = fullPath;
    }

    public String getPath(){
        String p[]=fullPath.split("/");
        String path="";
        //          /www/server/tomcat/webapps/cloud/upload/1234635/06_三人表决器的项目工程讲解.mp4
        for(int i=8;i<p.length;i++){
            path+="/"+p[i];
        }
        return path;
    }

    public Integer getFiletypeId() {
        return filetypeId;
    }

    public void setFiletypeId(Integer filetypeId) {
        this.filetypeId = filetypeId;
    }

//    public Date getUploadTime() {
//        return uploadTime;
//    }

    public String getStringTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        if(uploadTime==null)
            return "1900";
        return sdf.format(uploadTime);
    }

    public void setUploadTime(Date uploadTime) {
        this.uploadTime = uploadTime;
    }


    public String getFileFullSize() {
        int type=0;
        double size=fileSize;
        while(size>=1024){
            size/=1024.0;
            type++;
        }
        NumberFormat format=NumberFormat.getNumberInstance() ;
        format.setMaximumFractionDigits(1);
        fileFullSize = format.format(size);
        switch (type){
            case 1:fileFullSize+="\tKB";break;
            case 2:fileFullSize+="\tMB";break;
            case 3:fileFullSize+="\tGB";break;
            case 4:fileFullSize+="\tTB";break;
            default:fileFullSize+="\tB";
        }
        return fileFullSize;
    }

    public void setFileFullSize(String fileFullSize) { this.fileFullSize = fileFullSize; }
}